<template>
  <div class="app-container">
    <header class="app-header">
      <h1>Chat Assistant</h1>
      <div class="assistant-selector">
        <button 
          @click="changeAssistantType('general_assistant')" 
          :class="{'active': selectedTask === 'general_assistant'}"
        >
          一般助手
        </button>
        <button 
          @click="changeAssistantType('code_helper')" 
          :class="{'active': selectedTask === 'code_helper'}"
        >
          编程助手
        </button>
        <button 
          @click="changeAssistantType('product_manager')" 
          :class="{'active': selectedTask === 'product_manager'}"
        >
          产品助手
        </button>
      </div>
    </header>
    
    <main class="chat-main">
      <ChatBox ref="chatBox" />
    </main>
    
    <footer class="chat-footer">
      <div class="input-container">
        <input 
          type="text" 
          placeholder="输入消息..." 
          class="message-input"
          v-model="userInput"
          @keyup.enter="sendMessage"
        />
        <button class="send-button" @click="sendMessage">
          发送
        </button>
      </div>
    </footer>
  </div>
</template>

<script>
import ChatBox from './components/ChatBox.vue'

export default {
  name: 'App',
  components: {
    ChatBox
  },
  data() {
    return {
      userInput: '',
      selectedTask: 'general_assistant'
    }
  },
  methods: {
    sendMessage() {
      if (!this.userInput.trim()) return;
      
      // Pass the message directly to the ChatBox component using refs
      this.$refs.chatBox.receiveMessage(this.userInput);
      this.userInput = '';
    },
    
    changeAssistantType(task) {
      this.selectedTask = task;
      this.$refs.chatBox.changeAssistantType(task);
    }
  }
}
</script>

<style>
:root {
  --color-background: #f5f7fa;
  --color-background-alt: #ffffff;
  --color-primary: #4a6cf7;
  --color-secondary: #5d7aee;
  --color-accent: #11b981;
  --color-user: #4a6cf7;
  --color-bot: #f3f4f6;
  --color-text: #333333;
  --color-text-light: #6b7280;
  --color-border: #e5e7eb;
  
  --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --radius-md: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--color-background);
  color: var(--color-text);
  line-height: 1.5;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  background-color: var(--color-background-alt);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.app-header {
  padding: 1rem;
  background-color: var(--color-primary);
  color: white;
  text-align: center;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.assistant-selector {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.assistant-selector button {
  background-color: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.assistant-selector button:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

.assistant-selector button.active {
  background-color: white;
  color: var(--color-primary);
  font-weight: 500;
}

.chat-main {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.chat-footer {
  padding: 0.75rem 1rem;
  background-color: var(--color-background-alt);
  border-top: 1px solid var(--color-border);
}

.input-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.message-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
}

.message-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.send-button {
  padding: 0.75rem 1.25rem;
  background-color: var(--color-primary);
  color: white;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.send-button:hover {
  background-color: var(--color-secondary);
}
</style>